//
//  SEHospitalizeHeader.swift
//  SmartEyeForPatient
//
//  Created by QDSG on 2021/4/2.
//

import UIKit

typealias SEHospitalizeHeaderItemTapClosure = (SEHospitalizeHeaderItemType) -> Void
typealias SEHospitalizeHeaderAdvisoryClosure = () -> Void

class SEHospitalizeHeader: UIView {
    
    var headerItemClosure: SEHospitalizeHeaderItemTapClosure?
    var headerAdvisoryClosure: SEHospitalizeHeaderAdvisoryClosure?
    
    override func awakeFromNib() {
        super.awakeFromNib()
        advisoryView.setGradientColor([UIColor(hex: "#CFD1E8"), UIColor(hex: "#9EA6D4")],
                                      direction: .horizontal,
                                      targetView: advisoryLabel)
    }

    @IBOutlet var headerItems: [SEHospitalizeHeaderItem]! {
        didSet {
            headerItems.forEach {
                $0.itemTapClosure = { [weak self] (itemType, isClicked) in
                    if isClicked {
                        self?.headerItemClosure?(itemType)
                        return
                    }
                }
            }
        }
    }
    
    @IBOutlet private weak var advisoryView: UIView! {
        didSet {
            advisoryView.setLayerCorners(rect: advisoryView.bounds, radius: 10)
            advisoryView.setShadow()
            
            let tapGesture = UITapGestureRecognizer(target: self, action: #selector(_advisoryTap))
            advisoryView.addGestureRecognizer(tapGesture)
        }
    }
    
    @IBOutlet private weak var advisoryLabel: UILabel! {
        didSet {
            advisoryLabel.layer.cornerRadius = advisoryLabel.height / 2
        }
    }
    
    @IBOutlet weak var searchNavView: SEHospitalizeNavSearchView!
    
    @objc private func _advisoryTap() {
        headerAdvisoryClosure?()
    }
    
}
